export const _chineseToEnglish = (c) => {
  let idx = -1;
  const MAP = "ABCDEFGHJKLMNOPQRSTWXYZ";
  const boundaryChar = "驁簿錯鵽樲鰒餜靃攟鬠纙鞪黁漚曝裠鶸蜶籜鶩鑂韻糳";
  if (!String.prototype.localeCompare) {
    throw Error("String.prototype.localeCompare not supported.");
  }
  if (/[^\u4e00-\u9fa5]/.test(c)) {
    if (MAP.indexOf(c.toUpperCase()) == -1) {
      return "#";
    }
    return c.toUpperCase();
  }
  for (let i = 0; i < boundaryChar.length; i++) {
    if (boundaryChar[i].localeCompare(c, "zh-CN-u-co-pinyin") >= 0) {
      idx = i;
      break;
    }
  }
  return MAP[idx];
};
//排序
export const sortFind = (data) => {
  let users = [];
  data.forEach((item) => {
    let userIndex = users.findIndex(
      (user) => user.index == _chineseToEnglish(item.name)
    );
    if (userIndex !== -1) {
      users[userIndex].users.push(item);
    } else {
      users.push({
        index: _chineseToEnglish(item.name),
        users: [{ ...item }],
      });
    }
  });
  users.sort((a, b) => {
    return a.index.charCodeAt(0) - b.index.charCodeAt(0);
  });
  users.push(users[0]);
  users.splice(0, 1);
  return users;
};
